﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;

namespace SpeedTestReports.Web
{
    public class XAMLElement
    {
        private XmlElement element = null;
        private XmlDocument doc = null;

        public XmlElement Element
        {
            get
            {
                return element;
            }
        }

        public XAMLElement(string elementName, XmlDocument doc)
        {
            this.doc = doc;

            if (doc != null)
            {
                element = doc.CreateElement(elementName);
            }
        }

        public XAMLElement(string elementName, string prefix, string uri , XmlDocument doc)
        {
            this.doc = doc;

            if (doc != null)
            {
                element = doc.CreateElement(prefix, elementName, uri);
            }
        }

        public void AppendAttribute(string attribute, string attributeValue)
        {
            XmlAttribute nodeAttr = doc.CreateAttribute(attribute);
            nodeAttr.Value = attributeValue;
            element.Attributes.Append(nodeAttr);
        }

        public void SetXmlns()
        {
            XAMLUtil.SetXmlns(doc, ref element);
        }
    }

    public static class XAMLUtil
    {
        public static void SetXmlns(XmlDocument doc, ref XmlElement element)
        {
            XmlAttribute nodeAttr = doc.CreateAttribute("xmlns:controls");
            nodeAttr.Value = "clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls";
            element.Attributes.Append(nodeAttr);

            nodeAttr = doc.CreateAttribute("xmlns:dataInput");
            nodeAttr.Value = "clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input";
            element.Attributes.Append(nodeAttr);

            nodeAttr = doc.CreateAttribute("xmlns:generic");
            nodeAttr.Value = "clr-namespace:SpeedTestReports;assembly=SpeedTestReports";
            element.Attributes.Append(nodeAttr);

            nodeAttr = doc.CreateAttribute("xmlns:controlsToolkit");
            nodeAttr.Value = "clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit";
            element.Attributes.Append(nodeAttr);

            nodeAttr = doc.CreateAttribute("xmlns");
            nodeAttr.Value = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
            element.Attributes.Append(nodeAttr);
        }
    }

}
